const parameter = getApp().globalData.parameter
const domainName = getApp().globalData.domainName
const oss_domain = getApp().globalData.oss_domain

// pages/certified_my_paper/certified_my_paper.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    icon_url:oss_domain + 'static/picture/app_icon/',
    windowWidth:wx.getSystemInfoSync().windowWidth,
    menuButtonObject: wx.getMenuButtonBoundingClientRect(),
    name:'',
    id_no:'',
  },
   
  go_check(user_id,name,id_no){
    getApp().get_vibration()
    if(!user_id){
      wx.showModal({
        showCancel: false,
        title: '未获取到用户ID，请重启小程序或联系客服',
      })
      return 
    }else if(!name){
      wx.showModal({
        showCancel: false,
        title: '请填入姓名',
      })
      return 
    }else if(id_no.length!=18){
      wx.showModal({
        showCancel: false,
        title: '身份证号码不正确',
      })
      return 
    }
    wx.showModal({
      content: '确定开始认证吗？',
      title: '提醒',
      success: res => {
        if(res.confirm){
          wx.showLoading({title: '系统查询中...'})
          wx.request({
            url: domainName + '/cert_id_card',
            data: {
              user_id: user_id,
              name:name,
              id_no:id_no,
            },...parameter,
            success: res => {
              wx.hideLoading()
              console.log('res',res.data)
              wx.showModal({
                confirmText: '知道了',
                cancelText: '返回',
                content: res.data.res_text,
                title: res.data.res_title,
                success: res => {
                  if(res.cancel){
                    wx.navigateBack()
                  }
                },
              })
            },
          })
        }
      },
    })
  },


  // 返回
  back(){getApp().get_vibration(),wx.navigateBack()},
  // 输入身份证号码
  id_no(e){this.setData({id_no:e.detail.value})},
  // 输入真实姓名
  name(e){this.setData({name:e.detail.value})},
  // 实名认证
  check(){this.go_check(this.data.user_id,this.data.name, this.data.id_no)},


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // console.log('options',options)
    this.data.user_id = options.user_id
  },


})